<?php

namespace WeForge;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class WeForgeServiceProvider extends ServiceProvider
{
    use ConfiguresQueue, ExtendsQueues, RegistersCommands;

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->extendQueues();
        $this->registerCommands();
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->ensurePathsAreConfigured();
        $this->ensureQueueIsConfigured();
    }

    /**
     * Ensure the asset url / mix url are properly configured.
     *
     * @return void
     */
    protected function ensurePathsAreConfigured()
    {
        if (! isset($_ENV['WEFORGE_SERVICE_NAME'])) {
            return;
        }

        if (! Config::get('app.asset_url')) {
            Config::set('app.asset_url', $_ENV['ASSET_URL'] ?? '/');
        }

        if (! Config::get('app.mix_url')) {
            Config::set('app.mix_url', $_ENV['MIX_URL'] ?? '/');
        }
    }
}
